package com.day9_Map_test;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * @ClassName: HashMap_Demo
 * @Author: zw
 * @Description: 出百万拳，行万里路；
 * @Create 2024/3/10-10:49
 * @Version 1.0
 */
public class HashMap_Demo {
    public static void main(String[] args) {
        //   创建hashMap集合， 键是学生对象， 值是居住地
////，要求保证键的唯一性；
////    在学生类中重写两个方法
////    hashCode（） 和 equals（）；
        HashMap<Student, String> studentStringHashMap = new HashMap<>();
        Student s1 = new Student("zw",13);
        Student s4 = new Student("zw4",13);
        Student s3 = new Student("zw3",12);
        Student s2 = new Student("zw2",11);
        Student s5 = new Student("zw2",11);
        studentStringHashMap.put(s1, "县");
        studentStringHashMap.put(s4, "市");
        studentStringHashMap.put(s3, "镇");
        studentStringHashMap.put(s2, "村");
        studentStringHashMap.put(s5, "村");
        Set<Map.Entry<Student, String>> entrySet = studentStringHashMap.entrySet();
        for (Map.Entry<Student, String> sn :entrySet) {
            Student st = sn.getKey();
            String location = sn.getValue();
            System.out.println(st.getName() +":" + st.getAge() + ":" + location);
        }
    }
}
